import fs from 'fs';

export function toBase64(filePath: string, mime = 'image/jpeg') {
  const exists = fs.existsSync(filePath);
  if (!exists) {
    return {
      success: false,
      message: 'File not found',
      data: '',
    };
  }

  const buf = fs.readFileSync(filePath);
  const base64 = buf.toString('base64');
  const data = `data:${mime};base64,${base64}`;
  return {
    success: true,
    message: 'File encoded successfully',
    data,
  };
}
